<script setup>
import { useUserStore } from '@/stores/user'
import { showToast } from 'vant'
import { useRouter } from 'vue-router'

const userStore = useUserStore()
const router = useRouter()

const handleLogout = () => {
  userStore.clearUserInfo()
  showToast('退出成功')
  router.push('/login')
}
</script>

<template>
  <div class="mine-page">
    <div class="user-info" @click="router.push('/user/profile')">
      <img :src="userStore.avatar" class="avatar" />
      <div class="info">
        <div class="username">{{ userStore.username }}</div>
        <div class="uid">ID: {{ userStore.uid }}</div>
      </div>
      <van-icon name="arrow" class="arrow-icon" />
    </div>

    <div class="menu-list">
      <div class="menu-item" @click="router.push('/article/list?type=0')">
        <van-icon name="like-o" />
        <span>我的点赞</span>
      </div>
      <div class="menu-item" @click="router.push('/article/list?type=1')">
        <van-icon name="star-o" />
        <span>我的收藏</span>
      </div>
      <div class="menu-item" @click="router.push('/article/list?type=2')">
        <van-icon name="notes-o" />
        <span>我的文章</span>
      </div>
    </div>

    <div class="menu-list">
      <div class="menu-item" @click="router.push('/user/follow')">
        <van-icon name="friends-o" />
        <span>我的关注</span>
      </div>
      <div class="menu-item" @click="router.push('/user/fans')">
        <van-icon name="contact-o" />
       <span>我的粉丝</span>
     </div>
     <div class="menu-item" @click="router.push('/user/friends')">
       <van-icon name="contact" />
       <span>我的朋友</span>
     </div>
   </div>

   <div class="menu-list">
      <div class="menu-item" @click="router.push('/accompany/my')">
        <van-icon name="friends-o" />
        <span>我的结伴</span>
      </div>
    </div>
  
    <div class="logout">
      <van-button block type="danger" @click="handleLogout">退出登录</van-button>
    </div>
  </div>
</template>

<style scoped lang="scss">
.mine-page {
  min-height: 100vh;
  background: #f8f8f8;
  padding: 20px;

  .user-info {
    display: flex;
    align-items: center;
    padding: 20px;
    background: #fff;
    border-radius: 8px;
    margin-bottom: 20px;
    cursor: pointer;
    position: relative;

    .avatar {
      width: 60px;
      height: 60px;
      border-radius: 50%;
      margin-right: 15px;
    }

    .info {
      .username {
        font-size: 18px;
        font-weight: bold;
        margin-bottom: 5px;
      }

      .uid {
        font-size: 14px;
        color: #999;
      }
    }

    .arrow-icon {
      position: absolute;
      right: 20px;
      top: 50%;
      transform: translateY(-50%);
      color: #999;
    }

    &:active {
      opacity: 0.8;
    }
  }

  .menu-list {
    background: #fff;
    border-radius: 8px;
    padding: 10px 0;
    margin-bottom: 20px;

    .menu-item {
      display: flex;
      align-items: center;
      padding: 15px 20px;
      font-size: 16px;

      .van-icon {
        margin-right: 10px;
        font-size: 20px;
      }
    }
  }

  .logout {
    padding: 0 20px;
  }
}
</style>